home *** CD-ROM | disk | FTP | other *** search
- Path: admaix.sunydutchess.edu!ub!newserve!rebecca!rpi!not-for-mail
- From: rcauvin@natinst.com (Roger L. Cauvin)
- Newsgroups: comp.lang.c++.moderated,comp.lang.c++
- Subject: Re: Virtual Function in private part?
- Date: 8 Feb 1996 16:33:17 -0000
- Organization: National Instruments
- Sender: cppmods@netlab.cs.rpi.edu
- Approved: Dietmar.Kuehl@uni-konstanz.de
- Message-ID: <4fd8kd$9i7@netlab.cs.rpi.edu>
- References: <4fa17f$qk4@netlab.cs.rpi.edu>
- NNTP-Posting-Host: netlab.cs.rpi.edu
- X-Original-Date: 8 Feb 1996 15:36:33 GMT
-
- In article <4fa17f$qk4@netlab.cs.rpi.edu>, Paul.Henshaw@jrc.it wrote:
-
- > Though Roger's argument is (IMHO) valid in general, I have a specific example
- > where I feel I am justified in keeping virtual methods private:
- >
- > class ActiveObject {
- > public:
- > ActiveObject(void* data=NULL, options_t=Normal);
- > virtual ~ActiveObject();
- ...
- > private:
- > virtual void* main(void* data)=0;
- > }
- >
- > class ActiveSocketReader : public ActiveObject {
- > public:
- ...
- > }
- >
- > private:
- > virtual void* main(void* data);
- >
- > }
-
- [portion of example elided]
-
- > Since main should be called only by ActiveObject::ActivObject() main should
- > be private - however the derived class must be able to provide its own main
- > function in order to be useful.
-
- It is not necessarily the case that main should be called only by the
- ActiveObject base class. Consider a SpecialActiveSocketReader class
- derived from ActiveSocketReader. An instance of the
- SpecialActiveSocketReader is just like an instance of the
- ActiveSocketReader class, except that it performs some additional
- processing in the main member function. The first thing that the
- SpecialActiveSocketReader::main function should do is to call the
- ActiveSocketReader::main function. It cannot do so, however, because it
- was declared private instead of protected.
-
- class SpecialActiveSocketReader : public ActiveSocketReader
- {
- public:
- ...
- private:
- virtual void* main(void* data);
- };
-
- void * SpecialActiveSocketReader::main(void *data)
- {
- // Perform default processing.
- ActiveSocketReader::main(data); // <--- Compiler error: main is private.
-
- // Perform "special" extra processing.
- }
-
- By declaring main private, you are making it impossible to derive from
- ActiveSocketReader in this manner.
-
-
- Roger
-
- [ Articles to moderate: mailto:c++-submit@netlab.cs.rpi.edu ]
- [ Read the C++ FAQ: http://www.connobj.com/cpp/cppfaq.htm ]
- [ Moderation policy: http://www.connobj.com/cpp/guide.htm ]
- [ Comments? mailto:c++-request@netlab.cs.rpi.edu ]
-